﻿using System.ComponentModel.DataAnnotations;

namespace RuoVea.CodeGen.Models;

/// <summary>
/// 元数据字段表。
/// </summary>
public class FieldMetadata
{
    /// <summary>
    /// 主键
    /// </summary>
    [SugarColumn(IsPrimaryKey = true, IsIdentity = false, IsNullable = false)]
    public long Id { get; set; }

    /// <summary>
    /// 表Id
    /// </summary>
    [SugarColumn(IsNullable = false)]
    public long TableMetaId { get; set; }

    /// <summary>
    /// 获取或设置列名。
    /// </summary>
    public string DbColumnName { get; set; }


    /// <summary>
    /// 获取或设置列的别名。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string PropertyName { get; set; }

    /// <summary>
    /// 字段长度
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int Length { get; set; }

    /// <summary>
    /// 获取或设置数据类型。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string DataType { get; set; }


    /// <summary>
    /// 实体类类型
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string PropertyType { get; set; }

    /// <summary>
    /// 字段描述
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string Description { get; set; }

    /// <summary>
    /// 默认值
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string DefaultValue { get; set; }

    /// <summary>
    /// 获取或设置一个值，指示该列是否允许NULL。
    /// 默认为不允许NULL。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsNullable { get; set; } = false;

    /// <summary>
    /// 获取或设置一个值，指示该列是否为主键。
    /// 默认为非主键。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsPrimaryKey { get; set; } = false;

    /// <summary>
    /// 自增
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsIdentity { get; set; } = false;

    /// <summary>
    /// 获取或设置排序号。
    /// 默认为0。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int FieldSort { get; set; } = 0;

    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int? DecimalDigits { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int? SpecialType { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsJson { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsIgnore { get; set; }
    
    /// <summary>
    /// 子项
    /// </summary>
    [SugarColumn(IsIgnore = true)]

    [Navigate(NavigateType.OneToOne, nameof(FieldMetadata.Id))]
    public FieldMetadataExAvue? ExAvue { get; set; }


    /// <summary>
    /// 是否为搜索项
    /// </summary>
    [Display(Name = "是否为搜索项")]
    public bool? IsSearch { get; set; }

    /// <summary>
    /// 表格列中是否显示
    /// </summary>
    [Display(Name = "表格列中是否显示")]
    public bool? ColumnDisplay { get; set; }

    /// <summary>
    /// 表单新增时项是否显示
    /// </summary>
    [Display(Name = "表单新增时项是否显示")]
    public bool? AddDisplay { get; set; }

    /// <summary>
    /// 表单编辑时项是否显示
    /// </summary>
    [Display(Name = "表单编辑时项是否显示")]
    public bool? EditDisplay { get; set; }
}
